package com.mxl.service.cashorder.rule;

import javax.annotation.Resource;

import com.mxl.common.helper.ResponseErrorCode;
import com.mxl.common.rule.AbstractRule;
import com.mxl.dao.cashorder.impl.CardRuleDaoImpl;
import com.mxl.dao.cashorder.model.CardRule;
import com.mxl.service.cashorder.dto.CashOrderRequest;

public class CardRuleCheck extends AbstractRule {

	@Resource(name = "cardRuleDao")
	private CardRuleDaoImpl cardRuleDao;

	@Override
	protected boolean makeDecision(Object obj) throws Exception {
		// 根据卡号 卡密 的长度查询 卡是否符合规则 CARDRULE表
		CashOrderRequest c = (CashOrderRequest) obj;
		CardRule rule = cardRuleDao.getBosstype(c.getCardNo().trim().length(),
				c.getCardPwd().trim().length());
		if (rule == null) {
			c.setMsgId(ResponseErrorCode.CARD_NOT_SUPPER.getValue());
			return false;
		}
		c.setBossType(rule.getBossType());
		c.setCardType(rule.getCardType());
		c.setCardRegion(rule.getCardRegion());
		return true;
	}

}
